package com.unicom.office;

import com.unicom.office.builder.OfficeBuilder;
import com.unicom.office.config.OfficeConfig;
import com.unicom.office.func.FuncBase;
import com.unicom.office.impl.*;
import com.unicom.office.runtime.OfficeRuntime;
import com.unicom.office.var.VarItem;
import com.unicom.office.dataitem.DataItem;
import com.unicom.office.node.OfficeNode;
import com.unicom.office.parser.OfficeParser;
import com.unicom.office.unit.OfficeUnit;

import java.util.*;

class OfficeHelper {

//    public static void convert(String templatePath, String sourcePath, String targetTemplatePath, String targetPath, OfficeParser officeParser, OfficeBuilder officeBuilder) {
////        OfficeNode templateNode = parse(templatePath, officeParser);
////        OfficeNode sourceNode = parse(sourcePath, officeParser);
////        OfficeNode targetTemplateNode = parse(targetTemplatePath, officeParser);
////        List<OfficeUnit> units = render(node, null, officeRender);
////        build(units.get(0), targetPath, officeBuilder);
//    }
//
//    public static FuncBase parse(String sourcePath, OfficeParser officeParser){
//        return officeParser.parse(sourcePath);
//    }
//
//    public static void build(List<OfficeUnit> units, String targetPath, OfficeBuilder officeBuilder){
//        officeBuilder.build(units, targetPath);
//    }

//    public static Map<String, DataItem> normalizingData(Map<String, Object> data, OfficeConfig config) {
//        if(data == null) {
//            data = new HashMap<String, Object>();
//        }
//
//        Map<String, DataItem> result = new HashMap<String, DataItem>();
//
//        try {
//            Set<String> keySet = config.getVarItemMap().keySet();
//            for (String key : keySet) {
//                VarItem varItem = config.getVarItem(key);
//                Object value = data != null && data.containsKey(key) ? data.get(key) : null;
//                DataItem dataItem = varItem.createDataItem(value);
//                result.put(key, dataItem);
//            }
//        }catch(Exception ex){
//
//        }
//
//        return result;
//    }

    public static OfficeParser getDefaultParser(String extension){
        if("xlsx".equals(extension)) {
            return new XlsxParser();
        }else if("csv".equals(extension)){
            return new CSVParser();
        }else if("docx".equals(extension)){
            return new DocxParser();
        }else {
            throw new RuntimeException(String.format("暂不支持%s格式", extension));
        }
    }

    public static OfficeBuilder getDefaultBuilder(String extension){
        if("xlsx".equals(extension)) {
            return new XlsxBuilder();
        }else if("csv".equals(extension)){
            return new CSVBuilder();
        }else if("docx".equals(extension)){
            return new DocxBuilder();
        }else {
            throw new RuntimeException(String.format("暂不支持%s格式", extension));
        }
    }
}
